package com.zkh.myutils.template;

import java.util.HashMap;
import java.util.Map;

import com.zkh.myutils.utils.Assert;

/**
 * 模板标签，用来记录foreach和if
 */
public class TemplateTag {
	/**
	 * 标签名称，有：foreach、if、elif、else
	 */
	private String tagName;
	/**
	 * 开始标签结束索引
	 */
	private int beginEnd;
	/**
	 * 结束标签开始索引
	 */
	private int endStart;
	/**
	 * 属性
	 */
	private Map<String, String> attrs = new HashMap<>();
	/**
	 * 设置属性
	 * @param attrName 属性名
	 * @param attrValue 属性值
	 */
	public void setAttr(String attrName, String attrValue) {
		attrs.put(attrName, attrValue);
	}
	/**
	 * 获取属性值
	 * @param attrName 属性名
	 * @return
	 */
	public String getAttr(String attrName) {
		return attrs.get(attrName);
	}
	/**
	 * 获取属性值
	 * @param attrName 属性名
	 * @return
	 */
	public String getAttr(String attrName, String defaultValue) {
		return Assert.getIfNotNull(attrs.get(attrName), e->e, defaultValue);
	}
	public String getTagName() {
		return tagName;
	}
	public void setTagName(String tagName) {
		this.tagName = tagName;
	}
	public int getBeginEnd() {
		return beginEnd;
	}
	public void setBeginEnd(int beginEnd) {
		this.beginEnd = beginEnd;
	}
	public int getEndStart() {
		return endStart;
	}
	public void setEndStart(int endStart) {
		this.endStart = endStart;
	}
	@Override
	public String toString() {
		return "TemplateTag [tagName=" + tagName + ", beginEnd=" + beginEnd + ", endStart="
				+ endStart + ", attrs=" + attrs + "]";
	}
}
